package human;

import java.util.ArrayList;
import java.util.Date;

import logic.Localizator;

import course.Course;
import course.RegisteredCourse;

/**
 * This class describes a user entity in the project Elective.
 * 
 * @author Anton Ivinskyi
 * @version 0.021
 * 
 */

public class User {

	// Primary key section
	private Long id;

	// Storable parameters section
	private String name;
	private Long birthDate;
	private String email;
	private String password;
	private String degree;
	private String cardCode;
	private Short right;
	// Foreign key section
	private Long ownerId;

	// Objects section
	private User owner;

	// Lists section
	private ArrayList<Course> courseList = new ArrayList<Course>();
	private ArrayList<RegisteredCourse> registeredList = new ArrayList<RegisteredCourse>();

	/**
	 * Constructs empty User with <code>null</code> fields.
	 */
	public User() {
		this(false);
	}

	/**
	 * Constructs an empty User if parameter test is false, and a test user, if
	 * this parameter is <code>true</code> .
	 * 
	 * @param test
	 *            if true, creates test User with test values in fields
	 *            {@link #name}, {@link #birthDate}, {@link #cardCode},
	 *            {@link #degree}, {@link #email}, {@link #password}.
	 */
	public User(boolean test) {
		if (test) {
			this.setBirthDate(100000000L);
			this.setCardCode("TestCardCode");
			this.setDegree("Test Degreee");
			this.setEmail("test.student@test.email");
			this.setName("Test Student");
			this.setPassword("TestPassword");
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Long birthDate) {
		this.birthDate = birthDate;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDegree() {
		return degree;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}

	public String getCardCode() {
		return cardCode;
	}

	public void setCardCode(String cardCode) {
		this.cardCode = cardCode;
	}

	public Long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(Long ownerId) {
		this.ownerId = ownerId;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public ArrayList<Course> getCourseList() {
		return courseList;
	}

	public void setCourseList(ArrayList<Course> courseList) {
		this.courseList = courseList;
	}

	public ArrayList<RegisteredCourse> getRegisteredList() {
		return registeredList;
	}

	public void setRegisteredList(ArrayList<RegisteredCourse> registeredList) {
		this.registeredList = registeredList;
	}

	public String toString() {
		Date date = null;
		if (this.birthDate != null) {
			date = new Date(this.birthDate);
		}
		String s = "            User:" + 
			"\n        Id  " + this.getId() + 
			"\n      Name  " + this.getName() + 
			"\n    E-mail  " + this.getEmail();
		if (this.getPassword() != null) {
			s = s + "\n  Password  " + this.getPassword();
		}
		s += "\nBirth Date  " + Localizator.printDate(date) +
			 "\n Card Code  " + this.getCardCode() +
			 "\n    Degree  " + this.getDegree() + 
			 "\n  Owner Id  " + this.getOwnerId() + 
			 "\n     Right  " + this.getRight();
		return s;
	}

	public Short getRight() {
		return right;
	}

	public void setRight(Short right) {
		this.right = right;
	}

}
